class Solution
{
public:
    string reverseWords(string s)
    {
        string ret;
        int size = s.size();
        int i = 0;
        while (i < size)
        {
            int start = i;
            while (i < size && s[i] != ' ')
            {
                ++i;
            }
            int left = start, right = i - 1;
            while (left < right)
            {
                swap(s[left], s[right]);
                ++left;
                --right;
            }
            while (i < size && s[i] == ' ')
            {
                ++i;
            }
        }
        return s;
    }
};